Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add alternate domain names to cdn site host construct #84

Merged
merged 15 commits into from
Oct 27, 2023

Conversation

malcyL
Copy link
Contributor

@malcyL malcyL commented Oct 26, 2023

Problem

We have had outages to both smalti's internal UI and production elevate caused by the cloud front distribution deleting the alias for the live DNS name when a release is performed.

This is because we manually create the DNS entry and the cloud front distribution alias for it. We haven't included these in the cloud formation stack previously because we want to be able to follow a process of deploying a new stack alongside a live stack and switch to it when we are happy. We want to use DNS to do this in the same way we would when bringing up a new instance of a traditional web server.

If the DNS entry or the cloud front distribution alias are contained in the cloud formation stack, a new stack with a different watermark can not be created alongside the live production stack. The DNS entry and the cloud front distribution alias can not be duplicated in another stack - the stack creation fails.

Possible Solutions Discussed To Resolve This

These options are from this investigation ticket: https://github.com/talis/platform/issues/6436#issuecomment-1505271353

  1. Have the deployment job in CircleCI re-add the alias it after doing deploy.
  2. Include alternate domain name with the desired domain in the stack. Have a parameter to not include it, e.g. when we deploy into a new stack?
  3. Remove CloudFront distribution from app stack (move to a separate stack or to terraform?). Treat Cloudfront Distribution like a DB, we provision once and only once.

Option 1 - Pro - minimal change to code. Con - Potential short downtime on every release.
Option 2 - Pro - minimal change to code. Con - increase in complexity around deployments in hercules and individual projects
Option 3 - Pro - Deployment moved away from making any changes to Cloud Front. Con - this is a much bigger change

The decision was to go for Option 2. This PR implements that solution.

Changes in This PR

Changes to the construct:

  • adds a new property to CdnSiteHostingConstructProps called aliasSubDomains
  • any entries in aliasSubDomains are added as aliases to the cloud front distribution
  • when using CdnSiteHostingWithDnsConstruct, DNS entries are created for all aliases provided

A simple cdn site hosting construct example has been added to the examples section. This example:

  • deploys a website with CdnSiteHostingConstructProps
  • deploys a website with CdnSiteHostingWithDnsConstruct

The integration tests have been extended to run against this new sample project in the same way we have integration tests running against the other samples

The circle build has therefore been updated to deploy the new sample in parallel to it's deployments of the other samples.

The PR also adds a Best Practices section into the README to describe the imagined process for resolving this issue - changes are needed in both hercules and consuming projects.

Smoke Testing

We have tested running through the envisaged process of bringing up a new stack and making it live alongside an existing live stack.

I was concerned about the final step - cloud formation adding in the new alias which has actually been added manually at the time of the DNS change.

However, this step did work and there are no issues with future releases after the switch.

Details here: https://techfromsage.atlassian.net/browse/PLT-62?focusedCommentId=110708

@malcyL malcyL self-assigned this Oct 26, 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this test file in the example as its basically an empty file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generated automatically as a place holder with the cdk init --language typescript.

It's sort of nice as a place holder - but I will delete it.

Comment on lines 49 to 50
// aliases: [siteDomain],
aliases: aliases,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd be happier with this:

Suggested change
// aliases: [siteDomain],
aliases: aliases,
aliases: [siteDomain, ...aliases],

It makes it clear that the siteDomain is there and that it's the main one.

const aliases = props.aliasSubDomains
? props.aliasSubDomains.map((alias) => `${alias}.${props.domainName}`)
: [];
aliases.push(getSiteDomain(props));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I commented above, I don't think siteDomain should be here.

@malcyL malcyL changed the title PLT-62 Alternate domain names in CDN Site Host Construct feat: add alternate domain names to cdn site host construct Oct 27, 2023
@malcyL malcyL merged commit e9f7837 into main Oct 27, 2023
13 of 14 checks passed
@malcyL malcyL deleted the PLT_62_AlternateDomainNames branch October 27, 2023 09:37
@talisaspire
Copy link
Collaborator

🎉 This PR is included in version 3.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants